import request from '@/utils/request'
const baseURL = process.env.VUE_APP_USER_AUTH_URL
const baseURL2 = process.env.VUE_APP_BASE_URL
export function getToken() {

}
// 用户列表
export function getUserList(username) {
    return request({
        url: baseURL + `/user/show/filter?username=` + username,
        method: 'get',
    })
}
// 用户列表
export function getUserInfoList(data, deptIds = '') {
    return request({
        url: baseURL + '/user/list',
        method: 'post',
        data: {
            ...data,
            deptIds: deptIds ? deptIds.split(',') : undefined
        }
    })
}
export function getSuperlinkUser(params) {
    return request({
        url: baseURL2 + '/superlink/api/users',
        method: 'get',
        params,
    })
}
export function editPaw(params) {
    return request({
        url: baseURL + '/user/reset/password',
        method: 'get',
        params,
    })
}
export function getUserDetails(params) {
    return request({
        url: baseURL + '/user/get',
        method: 'get',
        params
    })
}
export function updateUser(data, tenantIds) {
    // const deptId = data.deptId ? data.deptId : ''
    // ?tenantIds=${tenantIds}&deptId=${deptId} tenantIds

    return request({
        url: baseURL + `/user/update`,
        method: 'put',
        data: {
            ...data,
            tenantCloneIds: undefined,
            tenantIds: tenantIds ? tenantIds.split(',') : undefined
        }
    })
}
// 添加用户
export function addUser(data, tenantIds) {
    // const deptId = data.deptId ? data.deptId : ''
    return request({
        url: baseURL + `/user/create`,
        method: 'post',
        data: {
            ...data,
            tenantCloneIds: undefined,
            tenantIds: tenantIds ? tenantIds.split(',') : undefined
        }
    })
}
// 删除
export function delUser(userIds) {
    return request({
        url: baseURL + '/user/delete?userIds=' + userIds,
        method: 'delete',
    })
}
// 租户
export function getAllTenant(userIds) {
    return request({
        url: baseURL + '/tenant/list/all',
        method: 'get',
    })
}
// 分配角色
export function useRoles(params) {
    return request({
        url: baseURL + '/user/assign/roles?roleIds=' + params.roleIds + '&userId=' + params.userId,
        method: 'get',
    })
}
// 分配角色 已分配
export function useAssignedRoles(params) {
    return request({
        url: baseURL + '/user/assigned/roles',
        method: 'get', params
    })
}
//角色列表
export function getRoleList(data) {
    return request({
        url: baseURL + '/role/list',
        method: 'post',
        data
    })
}
//角色列表 添加
export function addRoleList(data) {
    return request({
        url: baseURL + '/role/create',
        method: 'post',
        data
    })
}
//角色列表 添加
export function getRole(roleId) {
    return request({
        url: baseURL + '/role/get?roleId=' + roleId,
        method: 'get',
    })
}
//角色列表 编辑
export function updateRole(data) {
    return request({
        url: baseURL + '/role/update',
        method: 'put', data
    })
}
//角色列表 编辑
export function delRole(roleIds) {
    return request({
        url: baseURL + '/role/delete?roleIds=' + roleIds,
        method: 'delete',
    })
}
//菜单
export function getMenuTree(params) {
    return request({
        url: baseURL + '/menu/tree',
        method: 'get',
        params
    })
}
//资源
export function getRoleTree(params) {
    return request({
        url: baseURL + '/permission/tree',
        method: 'get',
        params
    })
}
// 分配菜单
export function useMenus(params) {
    return request({
        url: baseURL + '/role/assign/menus',
        method: 'get',
        params
    })
}
// 分配资源
export function usePermissions(params) {
    return request({
        url: baseURL + '/role/assign/permissions',
        method: 'get',
        params
    })
}
//菜单
export function getMenuList(data) {
    return request({
        url: baseURL + '/menu/list',
        method: 'post',
        data
    })
}
//资源
export function getPermissionList(data) {
    return request({
        url: baseURL + '/permission/list',
        method: 'post',
        data
    })
}
//资源-类型
export function getPerType() {
    return request({
        url: baseURL + '/permission/list/perType',
        method: 'get',
    })
}
// 拥有的路由
export function permissionMenu(userId) {
    return request({
        url: baseURL + '/menu/show?userId=' + userId,
        method: 'get',
    })
}
// 通过用户信息获取相关租户
export function getTenantList(params) {
    return request({
        url: baseURL + '/tenant/list/name',
        method: 'get', params

    })
}
// 通过用户信息获取相关租户
export function getUserInfo(params) {
    return request({
        url: baseURL + '/user/info',
        method: 'get', params

    })
}
// 获取鉴权token
export function getAuthToken(data) {
    return request({
        url: baseURL + '/oauth/token',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
        },
        auth: {
            username: 'iot_web',
            password: 'iot_web',
        }
    })
}